package com.aaa.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebFilter("/jump/*")
public class LoginFilter implements  Filter{

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest  req = (HttpServletRequest) request;
		HttpServletResponse  resp = (HttpServletResponse) response;
		//1 鑾峰彇session涓殑鐢ㄦ埛
		Object user = req.getSession().getAttribute("user");
		System.out.println(user);
		if(user == null) {
			//濡傛灉娌℃湁鐧诲綍 閲嶅畾鍚戝埌鐧诲綍鐣岄潰
			resp.sendRedirect(  req.getContextPath() +"/denglu.html"     );
		}else {
			// 濡傛灉宸茬粡鐧诲綍杩� 鍒欐斁琛�
			chain.doFilter(req, resp);
		}
		//fghfghfhjfhjg
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}
}
